home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / IFC_112 / netscape / application / PackConstraints.java < prev    next >
Encoding:
Text File  |  1999-05-28  |  9.8 KB  |  308 lines  |  [TEXT/CWIE]

  1. // PackConstraints.java
  2. // By Ned Etcode
  3. // Copyright 1995, 1996, 1997 Netscape Communications Corp. All rights reserved.
  4.  
  5. package netscape.application;
  6.  
  7. import netscape.util.*;
  8.  
  9. /** Object subclass describing constraints associated with a View managed by
  10.   * a PackLayout LayoutManager.  You will usually configure a PackConstraints
  11.   * instance appropriately and then associate this instance with a View using
  12.   * the PackLayout's <b>setConstraints()</b> method.<p>
  13.   * The default constraints are:<ul>
  14.   *   <li>anchor = ANCHOR_CENTER
  15.   *   <li>expand = false
  16.   *   <li>fillx = false
  17.   *   <li>filly = false
  18.   *   <li>ipadx = 0
  19.   *   <li>ipady = 0
  20.   *   <li>padx = 0
  21.   *   <li>side = SIDE_TOP
  22.   * </ul>
  23.   *
  24.   */
  25. public class PackConstraints extends Object implements Codable, Cloneable {
  26.     int         anchor;
  27.     boolean     expand;
  28.     boolean     fillX;
  29.     boolean     fillY;
  30.     int         iPadX;
  31.     int         iPadY;
  32.     int         padX;
  33.     int         padY;
  34.     int         side;
  35.  
  36.     final static String ANCHOR_KEY = "anchor",
  37.                         EXPAND_KEY = "expand",
  38.                         FILLX_KEY  = "fillx",
  39.                         FILLY_KEY  = "filly",
  40.                         IPADX_KEY  = "ipadx",
  41.                         IPADY_KEY  = "ipady",
  42.                         PADX_KEY   = "padx",
  43.                         PADY_KEY   = "pady",
  44.                         SIDE_KEY   = "side";
  45.  
  46.     /** Position View north of the allocated area. */
  47.     public static final  int ANCHOR_NORTH       = 0;
  48.     /** Position View northeast of the allocated area. */
  49.     public static final  int ANCHOR_NORTHEAST   = 1;
  50.     /** Position View east of the allocated area. */
  51.     public static final  int ANCHOR_EAST        = 2;
  52.     /** Position View southeast of the allocated area. */
  53.     public static final  int ANCHOR_SOUTHEAST   = 3;
  54.     /** Position View south of the allocated area. */
  55.     public static final  int ANCHOR_SOUTH       = 4;
  56.     /** Position View southwest of the allocated area. */
  57.     public static final  int ANCHOR_SOUTHWEST   = 5;
  58.     /** Position View west of the allocated area. */
  59.     public static final  int ANCHOR_WEST        = 6;
  60.     /** Position View northwest of the allocated area. */
  61.     public static final  int ANCHOR_NORTHWEST   = 7;
  62.     /** Position View centered within the allocated area. */
  63.     public static final  int ANCHOR_CENTER      = 8;
  64.  
  65.     /** Position View above the allocated area. */
  66.     public static final  int SIDE_TOP       = 0;
  67.     /** Position View below the allocated area. */
  68.     public static final  int SIDE_BOTTOM    = 1;
  69.     /** Position View to the left of the allocated area. */
  70.     public static final  int SIDE_LEFT      = 2;
  71.     /** Position View to the right of the allocated area. */
  72.     public static final  int SIDE_RIGHT     = 3;
  73.  
  74.     /** Constructs a PackConstraints with default constraints. */
  75.     public PackConstraints()    {
  76.         anchor = ANCHOR_CENTER;
  77.         expand = false;
  78.         fillX  = false;
  79.         fillY  = false;
  80.         iPadX  = 0;
  81.         iPadY  = 0;
  82.         padX   = 0;
  83.         padY   = 0;
  84.         side   = SIDE_TOP;
  85.     }
  86.  
  87.     /** Constructs a PackConstraints with the specified constraints. */
  88.     public PackConstraints(int anchor, boolean expand,
  89.                               boolean fillX, boolean fillY, int iPadX,
  90.                               int iPadY, int padX , int padY, int side) {
  91.         setAnchor(anchor);
  92.         setExpand(expand);
  93.         setFillX(fillX);
  94.         setFillY(fillY);
  95.         setInternalPadX(iPadX);
  96.         setInternalPadY(iPadY);
  97.         setPadX(padX);
  98.         setPadY(padY);
  99.         setSide(side);
  100.     }
  101.  
  102.  
  103.     /** Sets the location in which the View should be placed within its area.
  104.       * Used when the View is smaller than its allocated area.
  105.       */
  106.     public void setAnchor(int value)    {
  107.         if(value < ANCHOR_NORTH || value > ANCHOR_CENTER)
  108.             throw new InconsistencyException(this +
  109.                             "Invalid Anchor value: " + value);
  110.         anchor = value;
  111.     }
  112.  
  113.     /** Returns the anchor value.
  114.       * @see #setAnchor
  115.       */
  116.     public int anchor()    {
  117.         return anchor;
  118.     }
  119.  
  120.     /** Specifies whether the PackLayout should enlarge the View to fill any
  121.       * extra space within the View's allocated area.
  122.       */
  123.     public void setExpand(boolean value)    {
  124.         expand = value;
  125.     }
  126.  
  127.     /** Returns <b>true</b> if the PackLayout should enlarge the View to fill
  128.       * any extra space within the View's allocated area.
  129.       * @see #setExpand
  130.       */
  131.     public boolean expand()    {
  132.         return expand;
  133.     }
  134.  
  135.     /** Specifies whether the PackLayout should enlarge the View to fill any
  136.       * extra space along the X-axis of the View's allocated area.
  137.       */
  138.     public void setFillX(boolean value) {
  139.         fillX = value;
  140.     }
  141.  
  142.     /** Returns <b>true</b> if the PackLayout should enlarge the View to fill
  143.       * any extra space along the X-axis of the View's allocated area.
  144.       * @see #setFillX
  145.       */
  146.     public boolean fillX() {
  147.         return fillX;
  148.     }
  149.  
  150.     /** Specifies whether the PackLayout should enlarge the View to fill any
  151.       * extra space along the Y-axis of the View's allocated area.
  152.       */
  153.     public void setFillY(boolean value) {
  154.         fillY = value;
  155.     }
  156.  
  157.     /** Returns <b>true</b> if the PackLayout should enlarge the View to fill
  158.       * any extra space along the Y-axis of the View's allocated area.
  159.       * @see #setFillY
  160.       */
  161.     public boolean fillY() {
  162.         return fillY;
  163.     }
  164.  
  165.     /** Sets the padding the PackLayout adds to the View's minimum
  166.       * width.  The PackLayout forces the View's minimum width to its
  167.       * original minimum width plus twice its "internalPadX."
  168.       */
  169.     public void setInternalPadX(int value)  {
  170.         iPadX = value;
  171.     }
  172.  
  173.     /** Returns the View's "internalPadX."
  174.       * @see #setInternalPadX
  175.       */
  176.     public int internalPadX()  {
  177.         return iPadX;
  178.     }
  179.  
  180.     /** Sets the padding the PackLayout adds to the View's minimum
  181.       * height.  The PackLayout forces the View's minimum height to its
  182.       * original minimum height plus twice its "internalPadY."
  183.       */
  184.     public void setInternalPadY(int value)  {
  185.         iPadY = value;
  186.     }
  187.  
  188.     /** Returns the View's "internalPadY."
  189.       * @see #setInternalPadY
  190.       */
  191.     public int internalPadY()  {
  192.         return iPadY;
  193.     }
  194.  
  195.     /** Sets the padding the PackLayout adds to the View's width.  The
  196.       * PackLayout does not change the View's width, but it does create
  197.       * empty space "padX" pixels wide to the View's left and right.
  198.       */
  199.     public void setPadX(int value)  {
  200.         padX = value;
  201.     }
  202.  
  203.     /** Returns the View's "padX."
  204.       * @see #setPadX
  205.       */
  206.     public int padX()  {
  207.         return padX;
  208.     }
  209.  
  210.     /** Sets the padding the PackLayout adds to the View's height.  The
  211.       * PackLayout does not change the View's height, but it does create
  212.       * empty space "padY" pixels tall above and below the View.
  213.       */
  214.     public void setPadY(int value)  {
  215.         padY = value;
  216.     }
  217.  
  218.     /** Returns the View's "padY."
  219.       * @see #setPadY
  220.       */
  221.     public int padY()  {
  222.         return padY;
  223.     }
  224.  
  225.     /** Sets the side of the View's allocated area to which the PackLayout
  226.       * should attach the View.  Possible values are SIDE_TOP, SIDE_BOTTOM,
  227.       * SIDE_LEFT, and SIDE_RIGHT.
  228.       */
  229.     public void setSide(int value)  {
  230.         if(value < SIDE_TOP || value > SIDE_RIGHT)
  231.             throw new InconsistencyException(this +
  232.                             "Invalid Side value: " + value);
  233.         side = value;
  234.     }
  235.  
  236.     /** Returns the side of the View's allocated area to which the PackLayout
  237.       * should attach the View.
  238.       * @see #setSide
  239.       */
  240.     public int side()  {
  241.         return side;
  242.     }
  243.  
  244.  
  245.  
  246. /// Codable Interface
  247.     /** Describes the PackConstraints class' coding information.
  248.       * @see Codable#describeClassInfo
  249.       */
  250.     public void describeClassInfo(ClassInfo info)   {
  251.         info.addClass("netscape.application.PackConstraints", 1);
  252.         info.addField(ANCHOR_KEY, INT_TYPE);
  253.         info.addField(EXPAND_KEY, BOOLEAN_TYPE);
  254.         info.addField(FILLX_KEY, BOOLEAN_TYPE);
  255.         info.addField(FILLY_KEY, BOOLEAN_TYPE);
  256.         info.addField(IPADX_KEY, INT_TYPE);
  257.         info.addField(IPADY_KEY, INT_TYPE);
  258.         info.addField(PADX_KEY, INT_TYPE);
  259.         info.addField(PADY_KEY, INT_TYPE);
  260.         info.addField(SIDE_KEY, INT_TYPE);
  261.     }
  262.  
  263.     /** Encodes the PackConstraints.
  264.       * @see Codable#encode
  265.       */
  266.     public void encode(Encoder encoder) throws CodingException {
  267.         encoder.encodeInt(ANCHOR_KEY, anchor);
  268.         encoder.encodeBoolean(EXPAND_KEY, expand);
  269.         encoder.encodeBoolean(FILLX_KEY, fillX);
  270.         encoder.encodeBoolean(FILLY_KEY, fillY);
  271.         encoder.encodeInt(IPADX_KEY, iPadX);
  272.         encoder.encodeInt(IPADY_KEY, iPadY);
  273.         encoder.encodeInt(PADX_KEY, padX);
  274.         encoder.encodeInt(PADY_KEY, padY);
  275.         encoder.encodeInt(SIDE_KEY, side);
  276.     }
  277.  
  278.     /** Decodes the PackConstraints.
  279.       * @see Codable#decode
  280.       */
  281.    public void decode(Decoder decoder) throws CodingException {
  282.         anchor = decoder.decodeInt(ANCHOR_KEY);
  283.         expand = decoder.decodeBoolean(EXPAND_KEY);
  284.         fillX = decoder.decodeBoolean(FILLX_KEY);
  285.         fillY = decoder.decodeBoolean(FILLY_KEY);
  286.         iPadX = decoder.decodeInt(IPADX_KEY);
  287.         iPadY = decoder.decodeInt(IPADY_KEY);
  288.         padX = decoder.decodeInt(PADX_KEY);
  289.         padY = decoder.decodeInt(PADY_KEY);
  290.         side = decoder.decodeInt(SIDE_KEY);
  291.     }
  292.  
  293.     /** Finishes the PackConstraints decoding.
  294.       * @see Codable#finishDecoding
  295.       */
  296.     public void finishDecoding() throws CodingException {
  297.     }
  298.  
  299.     public Object clone()   {
  300.         try {
  301.             return super.clone();
  302.         } catch (CloneNotSupportedException e){
  303.              throw new InconsistencyException(this +
  304.                             ": clone() not supported :" + e);
  305.        }
  306.     }
  307. }
  308.